package thirdFragment.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import utils.VariousUtils;
import web.activity.WebPage;
import thirdFragment.bean.ExamBean;
import view.MyImageLoader;

/**
 * Created by Administrator on 2017/3/2.
 */

public class ExamLvAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<ExamBean.NewsListBean> arrayList;

    public ExamLvAdapter(Context context, ArrayList<ExamBean.NewsListBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyRteHolder myRteHolder ;
        if (convertView == null) {
            myRteHolder = new MyRteHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.exam_lv_item, null);
            myRteHolder.exam_item_comment = (TextView) convertView.findViewById(R.id.exam_item_comment);
            myRteHolder.exam_item_date = (TextView) convertView.findViewById(R.id.exam_item_date);
            myRteHolder.exam_item_content = (TextView) convertView.findViewById(R.id.exam_item_content);
            myRteHolder.exam_item_ima = (ImageView) convertView.findViewById(R.id.exam_item_ima);
            convertView.setTag(myRteHolder);
        } else {
            myRteHolder = (MyRteHolder) convertView.getTag();
        }
        myRteHolder.exam_item_comment.setText(arrayList.get(position).getComment());
        myRteHolder.exam_item_content.setText(arrayList.get(position).getTitle());
        myRteHolder.exam_item_date.setText(arrayList.get(position).getCreate_time());
        MyImageLoader.showImage(arrayList.get(position).getImage(),myRteHolder.exam_item_ima);

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, WebPage.class);
                i.putExtra("newsid", arrayList.get(position).getId());
                i.putExtra("url", VariousUtils.noHttps(arrayList.get(position).getLink()));
                context.startActivity(i);
            }
        });
        return convertView;

    }

    class MyRteHolder {
        TextView exam_item_content;
        TextView exam_item_date;
        TextView exam_item_comment;
        ImageView exam_item_ima;
    }
}
